// components/taskDetails/taskDetails.js
import QQMap from '../../../utils/qqmap'
Page({
  data: {
    latitude: 30.59982,
    longitude: 114.3096,
    scale: 18,
    markers: [
      {
        id: 1,
        latitude: 30.69982,
        longitude: 114.4096,
        width: 24,
        height: 30,
      },
      {
        id: 2,
        latitude: 30.59982,
        longitude: 114.3096,
        iconPath: '/static/images/marker.png',
        width: 40,
        height: 40,
      }],
    polyline: [],
  //   address: '',
  //   isShow: false,
  //   actions: [
  //     {
  //       name: '010-9987 0098',
  //       openType: 'share',
  //     },
  //   ],
  //   riShow: false,
  //   value: '',
  //   top: 0,
  //   main: '',
  //   activeNames: [],
  //   iconShow: false,
  //   nicList: [
  //     {
  //       url: 'https://img.yzcdn.cn/vant/leaf.jpg',
  //       name: '图片1',
  //     },
  //   ],
  //   bicList: [
  //     {
  //       url: 'https://img.yzcdn.cn/vant/leaf.jpg',
  //       name: '图片1',
  //     },
  //   ],

  },
  onLoad() {
    // 获取用户经纬度
    // this.getLocation()
    this.getAppInfo()
  },

  getAppInfo() {
    const res = wx.getSystemInfoSync()
    this.setData({ top: res.statusBarHeight })
  },
  onClickLeft() {
    wx.navigateBack({ delta: 1 })
  },
  /**
 * 组件的方法列表
 */
    async showMe() {
      const res = await wx.getLocation()
      this.setData({
        latitude: res.latitude,
        longitude: res.longitude
      })
    },
    goHome() {
      const t = wx.createMapContext("myMap", this)
      t.openMapApp({
        "longitude": 112.8993,
        "latitude": 30.40147,
        "destination": "潜江市"
      })
    },
    getPolyline() {
      QQMAP.direction({
        mode: 'bicycling',
        from: '30.59982,114.3096',
        to: '30.69982,114.4096',
        success: (res) => {
          // console.log(res);
          var ret = res;
          var coors = ret.result.routes[0].polyline, pl = [];
          //坐标解压（返回的点串坐标，通过前向差分进行压缩）
          var kr = 1000000;
          for (var i = 2; i < coors.length; i++) {
            coors[i] = Number(coors[i - 2]) + Number(coors[i]) / kr;
          }
          //将解压后的坐标放入点串数组pl中
          for (var i = 0; i < coors.length; i += 2) {
            pl.push({ latitude: coors[i], longitude: coors[i + 1] })
          }
          // console.log(pl)
          //设置polyline属性，将路线显示出来,将解压坐标第一个数据作为起点
          this.setData({
            latitude: pl[0].latitude,
            longitude: pl[0].longitude,
            polyline: [{
              points: pl,
              color: '#FF0000DD',
              width: 2
            }]
          })
        }
      })
  }
})
